package com.lxblyw.service;

import java.util.ArrayList;
import java.util.List;

import com.lxblyw.dao.EmployeeDao;
import com.lxblyw.dao.GoalDao;
import com.lxblyw.dao.TaskDao;
import com.lxblyw.entity.Employee;
//import com.liyawen.entity.Goal;
import com.lxblyw.entity.Task;
import com.lxblyw.entity.TaskItem;

public class TaskService {
	private TaskDao taskDao = new TaskDao(); 
	private EmployeeDao emDao = new EmployeeDao();
	//private GoalDao goalDao = new GoalDao();
	public List<TaskItem> list(String goalid) {
		List<Task> taskList =  taskDao.findByGoalId(goalid);
		List<TaskItem> taskItemList = new ArrayList<TaskItem>();
		for(Task task : taskList) {
			TaskItem taskItem = new TaskItem();
			Employee employee = emDao.findById(task.getEmployeeid());
			//Goal goal = goalDao.findById(task.getGoalid());
			taskItem.setTask(task);
			taskItem.setEmployee(employee);
			//taskItem.setGoal(goal);
			taskItemList.add(taskItem);
		}
		return taskItemList;
	}
	public void save(Task task) {
		taskDao.save(task);
	}
	public Task get(String id) {
		return taskDao.findById(id);
	}
	public void update(String name, String desc, String begintime,
			String endtime, String state, String level, String manager,
			String rate, String id) {
		taskDao.update(name,desc,begintime,endtime,state,level,manager,Integer.parseInt(rate),id);
	}
	public List<Task> getByEmployeeId(String id) {
		return taskDao.findByEmployeeId(id);
	}
}

